{layout name="common/layout" /}
<div class="main-order">
  <div class="main-title"><h2>订单管理</h2></div>
  {include file="common/alert" /}
  <div class="main-section">
    <div class="pull-left form-inline">
      <select id="btn_select" style="width:140px;margin-right:10px;" class="form-control">
        <option value="{:url('', array_merge($param, ['is_pay' => -1, 'is_taken' => -1, 'page' => 1]))}" {if $param.is_pay === -1 && $param.is_taken === -1}selected{/if}>显示所有</option>
        <option value="{:url('', array_merge($param, ['is_pay' => 1, 'is_taken' => 0, 'page' => 1]))}" {if $param.is_pay === 1 && $param.is_taken === 0}selected{/if}>已付款 未发货</option>
        <option value="{:url('', array_merge($param, ['is_pay' => 1, 'is_taken' => -1 ,'page' => 1]))}" {if $param.is_pay === 1 && $param.is_taken === -1}selected{/if}>已付款</option>
        <option value="{:url('', array_merge($param, ['is_pay' => -1, 'is_taken' => 1, 'page' => 1]))}" {if $param.is_pay === -1 && $param.is_taken === 1}selected{/if}>已发货</option>
      </select>
      {if $param.search !== ''}<strong>{$param.search}</strong> 搜索结果 <a href="{:url()}">清除条件</a></span>{/if}
      {if $param.user_id}客户编号{$param.user_id}的订单 <a href="{:url()}">清除条件</a></span>{/if}
    </div>
    <div class="pull-right">
      <form class="input-group" style="width:200px;">
          <input type="text" class="form-control" name="search" value="{$param.search}" placeholder="输入取餐码">
          <span class="input-group-btn">
            <input type="hidden" name="is_pay" value="{$param['is_pay']}">
            <input type="hidden" name=is_taken" value="{$param['is_taken']}">
            <input type="submit" class="btn btn-default" value="搜索">
          </span>
        </form>
    </div>
  </div>
  <div class="main-section">
      <table class="table table-striped table-bordered table-hover">
        <thead>
          <tr>
            <th width="100">取餐码</th>
            <th>商品清单</th>
            <th width="110">订单总价</th>
            <th width="130">下单时间</th>
            <th width="130">付款时间</th>
            <th width="130">发货时间</th>
            <th width="130">操作</th>
          </tr>
        </thead>
        <tbody>
          {foreach $order as $v}
          <tr>
            <td>{$v.code}</td>
            <td>
              <div style="display:inline-block;line-height: 22px;">
              {foreach $v.order_food as $vv}
                <div><span>{$vv.name}*{$vv.number}</span>　<small style="float:right;color:#888">单价 ¥{:floatval($vv.price)}</small></div>
              {/foreach}
              </div>
            </td>
            <td>
              <span></span>¥{:floatval($v.price)}</span>
              {if $v.promotion !== '0.00'}<br><small>(已优惠 ¥{:floatval($v.promotion)})</small></td>{/if}
            <td><small>{$v.create_time}</small></td>
            <td>{if $v.is_pay}<small>{$v.pay_time}</small>{else}未付款{/if}</td>
            <td>{if $v.is_taken}<small>{$v.taken_time}</small>{else}<span style="color:#C13932;"></span>未发货</span>{/if}</td>
            <td>
              {if $v.is_pay}{if $v.is_taken}
              <a class="js-taken" href="{:url('', $param)}" data-id="{$v.id}" data-val="0">取消</a>
              {else}
              <a class="js-taken" style="color:#F06C00;font-weight:600" href="{:url('', $param)}" data-id="{$v.id}" data-val="1">发货</a>
              {/if}{/if}
            </td>
          </tr>
          {/foreach}
          {if $order->isEmpty()}
          <tr><td colspan="7" class="text-center">列表为空</td></tr>
          {/if}
        </tbody>
      </table>
    </div>
    <div class="main-section">
      {$order|raw}
    </div>
</div>
<script>
    $('#btn_select').change(function() {
      var val = $(this).val();
      if (val) {
        location.href = val
      }      
    });
    $('.js-taken').click(function () {
      var url = $(this).attr('href');
      var id = $(this).attr('data-id');
      var val = $(this).attr('data-val');
      Common.form(url, { action: 'taken', id: id, val: val }).append('{:token()}').submit();
      return false;
    });
  </script>